Package Manager ANE implementing access to the Android Package Manager from Adobe AIR
The extension is available here: com.distriqt.PackageManager
There are two methods to retrieve the installed application information, asynchronous and synchronous. We suggest the async method as it shouldn’t affect the ui as much as the synchronous method may do, depending on the device and the number of applications installed.
Which ever method you use, the end result is an Array
of PackageInfo
objects. These objects contain:
packageName
: The java package name of the applicationlabel
: The name of the applicationversionName
: The version name of this package, as specified by the manifest tag’s versionName
attributeversionCode
: The version code for the applicationalong with other information detailed in the asdocs.
In order to retrieve a list of applications that are installed on the device call the getInstalledApplicationsAsync()
function.
You can use either a callback passed to the function or listen for the PackageManagerEvent.GET_INSTALLED_APPLICATIONS
event (or both)
Listening for the event involves adding a listener for PackageManagerEvent.GET_INSTALLED_APPLICATIONS
and then processing the result in the handler:
PackageManager.service.addEventListener(
PackageManagerEvent.GET_INSTALLED_APPLICATIONS,
getInstalledApplicationsHandler
);
PackageManager.service.getInstalledApplicationsAsync();
function getInstalledApplicationsHandler( event:PackageManagerEvent ):void
{
var installedPackages:Array = event.data;
if (installedPackages != null)
{
for each (var packageInfo:PackageInfo in installedPackages)
{
trace( packageInfo.packageName );
}
}
}
Alternatively you can do the similar thing with a callback:
PackageManager.service.getInstalledApplicationsAsync(
function( installedPackages:Array ):void
{
if (installedPackages != null)
{
for each (var packageInfo:PackageInfo in installedPackages)
{
trace( packageInfo.packageName );
}
}
}
);
You can also call getInstalledApplications()
to directly retrieve an array of the application package information however be aware that this call may take some time.
var installedPackages:Array = PackageManager.service.getInstalledApplications();
if (installedPackages != null)
{
for each (var packageInfo:PackageInfo in installedPackages)
{
trace( packageInfo.packageName );
}
}